<?php
namespace app\tp\controller;  // 必须继承于app 第二个是具体的应用名  例 t5/note/tp
use think\Controller;
//use think\Request;
use app\index\common\controller\Nav as commonNav;  // app可以看成就是note 调用公共模块
use app\tp\model\Listt;  //必须继承于app 第二个是具体的应用名  例 t5/note/tp 第三个首字母大写
use app\tp\model\Test;  //必须继承于app 第二个是具体的应用名  例 t5/note/tp 第三个首字母大写
use think\config;


// use think\Db;
class Index extends Controller
{
	public function _initialize()
    {
        echo ' 前置操作 在所有的方法使用之前，都要加这一句，可以用于记录客户访问过哪些页面，判断是否已登录 <br/>';
    }

	
    public function index()
    {
		$common = new commonNav();  // 调用公共模块
	    $data6 =  $common->index();
		$data = $common->index2();
	 dump($data);
	    $this->assign('data',$data);  //获得0级菜单
		$this->assign('data6',$data6); //获得具体数据

        $thinkphp_caidan = $this->get_thinkphp_caidan();  // 获得thinkphp 的分类菜单
        //dump($thinkphp_caidan);
		$this->assign('thinkphp_caidan',$thinkphp_caidan); 
		
		//获得thinkphp 菜单下的具体内容
		$erji_neirong = $this->get_erji_neirong();
		$this->assign('erji_neirong',$erji_neirong);
	    return $this->fetch();
	
	}
	
	public function get_thinkphp_caidan(){
		$model = new Listt;
      $where['superior'] = 9;
	  $order = null;
	  $item = null;
	  $limit = false;
	  $data = $model->select2($where,$order,$limit,$item); //获得0级菜单
	  return $data;
	}

	public function get_erji_neirong(){
	$data5 = array(); //页面遍历时使用的数组
		$data4 = array();
		$data6 = array();
		$model = new Listt();
		
		$data = $this->get_thinkphp_caidan();
		
		$order = null;
        $item = null;
        $limit = false;


		//获得一个新的数组 由 idname 和新的遍历内容组成 但是id 是衔接
		for($i=0; $i<count($data); $i++){
		$where2['superior'] = $data[$i]['id'];
		$data2 = $model->select2($where2,$order,$limit,$item); // 按上级菜单，遍历
		// 1.2 下面 如果data2 有值，重新改结构，相同 上级菜单 合并成一个数组包括 data 和idname
		if($data2){
			//1.1下面 遍历 相同 上级菜单 合并成一个数组
			for($n=0; $n<count($data2); $n++){
        $data3 =array(
                      'id'=> $data2[$n]['id'],
					  'content'=> $data2[$n]['content'],
					  'address'=> $data2[$n]['address'],
					  'url'=> $data2[$n]['url'],
		);
		 array_push($data4,$data3);
		}
			//1.1上面 遍历	相同 上级菜单 合并成一个数组
			$data4 = array('data'=>$data4);
			$idname = array('idname'=>$data[$i]['idname']);  //把一个字符串 转 键值对 数组
			$data5 = array_merge($data4, $idname); // 合并两个数组
			$data3 =  array();  // 重置数组为空
			$data4 =  array();  // 重置数组为空
		//	dump($data5);
			
				}
			// 1.2 上面 如果data2 有值，重新改结构，相同 上级菜单 合并成一个数组包括 data 和idname
			if($data5){
			array_push($data6,$data5);}
			$data5 =  array();  // 重置数组为空
	
	
			}
		//	dump($data6);
		 return $data6;
	}





	public function getConfg()
    {
		$res = config();
		echo '
		<pre>
		
		public function _initialize()
        {
        echo "在所有stock/index的方法使用之前，都要加这一句，可以用于记录客户访问过哪些页面<br/>"\;
		 }
		 echo"调用助手函数的第三种方法，需配置头部use think\config;加助手函数";
		 $res = config();
		 dump($res);
		</pre><hr/>
		';

		
		dump($res);
	}

	

	public function index2()
    {
		$res = [
			'code' =>200,
			'result'=>[
			   'list' => [1,2,3,4,5,6]   
			]
			];
		 Config::set('default_return_type','json');
		 echo "
		 <pre>
		 public function index2()
		 {
			 \$res = [
				 'code' =>200,
				 'result'=>[
					'list' => [1,2,3,4,5,6]   
				 ]
				 ];
			  Config::set('default_return_type','json');
			  return \$res;
				}
			  </pre>得到<br/>
		 ";
    
		 return $res;
	
	}

	public function index3()
    {
		$res = [
			'code' =>200,
			'result'=>[
			   'list' => [1,2,3,4,5,6]   
			]
			];
		echo"
		<pre>
		public function index3()
         {
		 \$res = [
			'code' =>200,
			'result'=>[
			   'list' => [1,2,3,4,5,6]   
			]
			];
			return json(\$res);
			</pre>得到<hr/>
		";
         return json($res);
	}

	public function index4()
    {
	 

	 
	  echo"
	  <pre>
	  public function index4()
    {
	  
	  return json(\$res);
	}
	  </pre>得到<hr/>
	  ";
	
	}

	

	public function index6()
	{
		echo"
		<pre>
		public function index6()
	{
		return view('gid/show');
	}
		</pre><hr/>
		";
	  return view('gid/show');
	}

	public function index7()
	{
		echo"
		<pre>
		public function index7()
	{
		return \$this->fetch('gid/show');
	}
		</pre><hr/>
		";
		return $this->fetch('gid/show');
	}


	public function index8(){
		echo"
		<pre>
		public function index8(){
			dump(\$_SERVER);
	       }
		</pre><hr/>
		";
		dump($_SERVER);
	}

	public function index9(){
		return $this->fetch();
	}

	public function index10(){
		return $this->fetch();
	}

public function index11(){
	$empty = "当没有遍历出数据时的默认输出";
		$list ="";
	$this->assign('name','在模版使用md5加密');
	$this->assign('user','abcdefghi');
	$this->assign('time',time());
	$this->assign('a','10');
	$this->assign('b','15');
	$this->assign('empty',$empty);
	$this->assign('list',$list);
	return $this->fetch();
	}
	public function index12(){
		$empty = "当没有遍历出数据时的默认输出";
			$list ="";
	
		$this->assign('empty',$empty);
		$this->assign('list',$list);
		return $this->fetch();
		}

		public function index13(){
			$model = new Listt();
			$data = $model->select();
			echo "
			<hr/>
			<pre>
			需model层的基础用法
			需头部 use app\tp\model\Listt; 
			需model 层
			\$model = new Listt();
			\$data = \$model->select();
			</pre>
			<hr/>
			";
            dump($data);
		}

	

		public function index15(){
			$model = new Listt();
			$data = $model->select();
			echo "
			<hr/>
			<pre>
			需model层的基础用法 
			需头部 use app\tp\model\Listt; 
			需model 层
			\$model = new Listt();
			\$data = \$model->select();
			echo Listt::getlastsql();  // model 下获得最后一条sql
			</pre>
			<hr/>
			";
			echo Listt::getlastsql();
            dump($data);
		}

		public function index16(){
			$name = input('get.name','何get');
			$age = input('get.age',101,'intval');
			
			//新增 创建 增加 数据 creat
			$model = new Test();
			$up = [
				'name'=> $name,
				  'age'=>$age
				];
			$this->index17();
			$data = $model->index2($up);
			echo"<br/>可以返回 新增数据是 第几条id<br/>";
			echo Listt::getlastsql();
			dump($data);
			dump($data->id);
		}

		public function index17(){
			echo"
			<hr/>
			<pre>
			头部
			namespace app\tp\controller;  // 必须继承于app 第二个是具体的应用名  例 t5/note/tp
			use think\Controller;
			use app\tp\model\Listt;  //必须继承于app 第二个是具体的应用名  例 t5/note/tp 第三个首字母大写



			//新增 创建 增加 数据 creat
			\$name = input('get.name','何get');
			\$age = input('get.age',101,'intval');
			\$model = new Test();
			\$up = [
				'name'=> \$name,
				  'age'=>\$age
				];
			
			\$data = \$model->index2(\$up);
			
			echo Listt::getlastsql();
			dump(\$data);
			dump(\$data->id); //返回新增数据是第几条id



			model层
			public function index2(\$up)
			{
            \$res = \$this->create(\$up); 
			return \$res;
			</pre>
			<hr/>
			";
		}


		public function index18()
		{
			$testModel = new Test;
			$testModel->name = '找事';
			$testModel->age = '100';
			$this->index19();
			$testModel->save();
			echo $testModel->getlastsql();
			dump($testModel->id);
		}	
  
		public function index19()
		{
			echo"
			<hr/>
			<pre>
			头部
			namespace app\tp\controller;  // 必须继承于app 第二个是具体的应用名  例 t5/note/tp
			use think\Controller;
			use app\tp\model\Test;  //必须继承于app 第二个是具体的应用名  例 t5/note/tp 第三个首字母大写


			\$testModel = new Test;
			\$testModel->name = '找事';
			\$testModel->age = '100';
			\$testModel->save();
			echo \$testModel->getlastsql(); //获得最后一条sql
			dump(\$testModel->id);
			</pre>
			<hr/>
			";
		}	

		public function index20(){
			//新增 创建 增加 数据 save
			$model = new Test();
			$up = [
				'name'=> '何发给',
				  'age'=>'100'
				];
		    $this->index21();
			$data = $model->index3($up);
			echo Listt::getlastsql();
			dump($data);
		}

		public function index21(){
			echo"
			<hr/>
			<pre>
			//新增 创建 增加 数据 save
			\$model = new Test();
			\$up = [
				'name'=> '何发给',
				  'age'=>'100'
				];
			\$data = \$model->index3(\$up);
			echo Listt::getlastsql();
			dump(\$data);  //收到 影响了一条数据


			model层
			\$res = \$this->save(\$up); 
             return \$res;
			</pre>
			<hr/>
			";
		}

		public function index22(){

			$model = new Test();
			// echo'有id 就可以修改数据了 返回 对象 2 返回一维数组的取出 和模版表示';
			$up = [
			   'id'=>'12',
			   'address'=>'被修改的地址'
			   ];
			$data = $model->index4($up);
			$this->index23();
            echo"用对象取出id";
			dump($data->id);
			echo"用数组取出id";
			dump($data['id']);
			dump($data);
		}
	
		public function index23(){
			 echo"
			  <hr/>
			  <pre>  
			  \$model = new Test();
			
			   \$up = [
				  'id'=>'12',    // id作为索引
				  'address'=>'被修改的地址'
				   ];
			  \$data = \$model->index4(\$up);
			 
			  echo'用对象取出id';
			  dump(\$data->id);
			  echo'用数组取出id';
			  dump(\$data['id']);
			  dump(\$data);
			 

			  model层
			  public function index4(\$up)
			  {
				 \$res = \$this->update(\$up);
				  return  \$res;
			   }

			 
			  </pre>
			  <hr/>
			   ";
            }

			public function index24(){
				$name = '找事';
				$logic = 'eq';  //等于
				$name = [$logic,$name];  //相当于 ['eq','找事']
				
				$model = new Test();
				$up = [
                    'address'=>'修改后的值6'
					];
				$map = [
					'name'=> $name
					];
				$this->index25();	
				  $data = $model->index5($up,$map);
				  dump($data);
			}

			public function index25(){
				   echo"
				   <hr/>
				   <pre>
				   \$name = '找事';
				   \$logic = 'eq';  //等于
				   \$name = [\$logic,\$name];  //相当于 ['eq','找事']
				    \$model = new Test();
				       \$up = [
                          'address'=>'修改后的值6'
					          ];
				       \$map = [
					        'name'=> \$name
					          ];
				        \$this->index25();	
				        \$data = \$model->index5(\$up,\$map);
				        \dump(\$data);
				   


					model 层
					\$res = \$this->where(\$map)->update(\$up);
					return \$res;

				   </pre>
				   <hr/>
				   ";
			}

      	public function index26(){
				echo"
				<hr/>
				<pre>
				向index5()5 函数传递出2个参数
				\$model->index5(\$up,\$map);

                index5函数 接受2个参数
				public function index5(\$up,\$map)
				</pre>
				<hr/>
				";
			}

			/**
			 * 根据条件修改数据
			 */
			public function index27(){
				$age = '112';
				$logic = 'gt';  //等于
				$age = [$logic,$age];  //相当于['gt','110']


				$model = new Test();
				$up = [
                    'address'=>'age大于112，则修改'
					];
				$map = [
					'age'=> $age
					];
				$this->index28();
				  $data = $model->index5($up,$map);
				  dump($data);

			}

			public function index28(){
			   echo"
				<hr/>
				<pre>  
				\$age = '112';
				\$logic = 'gt';  //等于
				\$age = [\$logic,\$age];  //相当于['gt','110']

				\$model = new Test();
				\$up = [
                    'address'=>'age大于112，则修改'
					];
				\$map = [
					'age'=> \$age  //gt 等于
					];
				
				  \$data = \$model->index5(\$up,\$map);
				  dump(\$data);
			 


				  model 层
				  \$res = \$this->where(\$map)->update(\$up);
				  return \$res;
			 
			   </pre>
			   <hr/>
			   ";
			}
/**
 * 修改数据 根据条件 闭包函数
 */

			public function index29(){
				$age = 110;
				$logic = 'gt';
			
				$model = new Test();
				$up = [
                    'address'=>'age大于110，则修改6'
					];
					$map = function($query)use($age,$logic){
						// $query->where('age','>','110');
						$query->where('age',$logic,$age);  //相当于where('age','gt','110');
						};
				 $this->index30();
				  $data = $model->index5($up,$map);
				  dump($data);
			 }
			 
			 public function index30(){
				 echo"
				 <hr/>
				 <pre>
				 \$age = 110;
				 \$logic = 'gt';

				    \$model = new Test();
				    \$up = [
                          'address'=>'age大于110，则修改2'
					       ];
						   \$map = function(\$query)use(\$age,\$logic){
						
							\$query->where('age',\$logic,\$age);  //相当于where('age','gt','110');
						   
						};
					\$data = \$model->index5(\$up,\$map);
					dump(\$data);



					model 层
					\$res = \$this->where(\$map)->update(\$up);
					return \$res;
				</pre>
				<hr/>	
				";
					}

					/**
					 * 批量修改
					 */

					public function index31(){
						$up = [
							['id'=>4,'address'=>'被批量修改121'],
							['id'=>23,'address'=>'被批量修改212'],
							['id'=>29,'address'=>'被批量修改212'],
						   ];
						   $model = new Test();   
						   $data = $model->index6($up);
						   $this->index32();
						   dump($data);
					}
		
					public function index32(){
					  echo"
					 <hr/>
					 <pre> 
					 \$up = [
						['id'=>4,'address'=>'被批量修改1'],
						['id'=>23,'address'=>'被批量修改2']
					   ];
					  \$model = new Test();   
					  \$data = \$model->index6(\$up);
                    <br/><br/><br/>
					 model层
					 \$res = \$this->saveAll(\$up);
					 return \$res;

					 <pre/>
					 <hr/>
					  ";
                 }
                /**
				 * 删除 返回影响了一条记录
				 */
				 public function index33(){
					$up = [
						'id'=>'24'
					   ];
					   $model = new Test();
					   $data = $model->index7($up);
					$this->index34();   
                    dump($data);
				 }

				 public function index34(){
					echo"
					<hr/>
					<pre>
					\$up = [
						'id'=>'24'
					   ];
					   \$model = new Test();
					   \$data = \$model->index7(\$up);
                    <br/><br/><br/><br/>
					model ceng
					\$res = \$this->destroy(\$up);
					return \$res;
					</pre>
					<hr/>
					";
				 }

				  /*
				   *删除 批量 使用闭包 返回 被影响了几条数据
				   */ 
				  public function index35(){
					   $id = 42;
					   $logic = 'gt';  // 大于

					$up = function($query)use($id,$logic){
						$query->where('id',$logic,$id);
					};
					   $model = new Test();
					   $data = $model->index7($up);
					$this->index36();   
                    dump($data);
				 }

				 public function index36(){
				echo"
				<hr/>
				<pre>
				\$id = 42;
				\$logic = 'gt';  // 大于

				\$up = function(\$query)use(\$id,\$logic){
					\$query->where('id',\$logic,\$id);
				};
				   \$model = new Test();
				   \$data = \$model->index7(\$up);
				   <br/><br/><br/><br/>
				   model 层
				   \$res = \$this->destroy(\$up);
				   return \$res;

				</pre>
				<hr/>
				";
				 }

                /*
				 * order 的写法
				 */ 
				 public function index37(){
                 echo'
				 <hr/>
				 <pre>
				 $order = "age desc";  //按年龄排序 由大到小
				 $order = "age";  //按年龄排序 由小到大
				 $order = "age,height desc";  // 按 年龄 从小到大 身高从大到小
				 <br/>
				 如果你的字段和mysql关键字有冲突，建议采用数组方式调用
				 $order = [
					"age",  //年龄 从小到大
					"height"=>"desc"  //身高 从大到小 
				];
				 </pre>
				 <hr/>
				 ';
				 }

				 /**
				  * 删除 delete 方法 根据条件删除 返回影响了几条数据
				  */
			public function index38(){
				$name="何发给25";
				$logic = "eq";  //等于
				$map = function($query)use($name,$logic){
					$query->where("name",$logic,$name);
					};
				   $model = new Test();
				   $data = $model->index8($map);
				   $this->index39();
			    dump($data);
					}

			public function index39(){
			echo'
			<hr/>
			<pre>
			$name="何发给25";
			$logic = "eq";  //等于

			$map = function($query)use($name,$logic){
				$query->where("name",$logic,$name);
				};
			   $model = new Test();
			   $data = $model->index8($map);
			   <br/><br/><br/><br/>
               model 层
			   $res = $this->where($map)->delete();
			   return $res;		
			</pre>
			<hr/>
			';
			}



			
			/**
			 * 统计 model层 共有多少条记录
			 */

			public function index40(){
				$model = new Test();
				$where = null;   
				$data = $model->index9($where);
				$this->index41();
				dump($data);
			}


			public function index41(){
			   echo"
			   <hr/>
			   <pre>  
			   \$model = new Test();
			   \$where = null;   
			   \$data = \$model->index9(\$where);
			   <br/><br/><br/><br/>
			   model 层
			   return \$this->where(\$map)->count();
			   </pre>
			   <hr/>
			   ";

			}
            /***
			 * 统计 共有多少条记录
			 */
			public function index42(){
				$name = '何发给1';
				$logic = 'eq';  // 等于
				$model = new Test();
				$where =  [
					'name'=> [$logic,$name]  //eq 等于
					  ];  
				$data = $model->index9($where);
				$this->index43();
				dump($data);
			}

			public function index43(){
				echo"
				<hr/>
				<pre>
				\$name = '何发给1';
				\$logic = 'eq';  // 等于
				\$model = new Test();
				\$where =  [
					'name'=> [\$logic,\$name]  //eq 等于
					  ];  
				\$data = \$model->index9(\$where);
				<br/><br/><br/><br/>
				model 层
				return \$this->where(\$map)->count();

                </pre>
				<hr/>
				";
			}


			/***
			 * 统计 根据条件 最大值
			 */
			public function index44(){
				$id = 30;
				$logic = 'gt';
				$model = new Test();
				$map = function($query)use($logic,$id){
					$query->where('id',$logic,$id);
					};
				$column = 'id';	
				$data = $model->index10($map,$column);
				
				$this->index46();
				echo Test::getlastsql();  // model 下获得最后一条sql
                dump($data);
        	}

			public function index45(){
				$model = new Test();
				$map = null;
				$column = 'age';	
				$data = $model->index10($map,$column);
				$this->index47();
				echo Test::getlastsql();  // model 下获得最后一条sql
                dump($data);
			}
			
			public function index46(){
			echo"
			<hr/>
			<pre>
			\$id = 30;
			\$logic = 'gt';
			\$model = new Test();
			\$map = function(\$query)use(\$logic,\$id){
				\$query->where('id',\$logic,\$id);
					};
				\$column = 'id';	
				\$data = \$model->index10(\$map,\$column);
				<br/><br/><br/><br/>
				model 层
				return \$this->where(\$map)->max(\$column);
			</pre>
			<hr/>	
			";
				}

				public function index47(){
				echo"
				<hr/>
				<pre>
				\$model = new Test();
				\$map = null;
				\$column = 'age';	
				\$data = \$model->index10(\$map,\$column);
				<br/><br/><br/><br/>
				model 层
				return \$this->where(\$map)->max(\$column);
                </pre>
				<hr/>
				";
					}

          /**
           * 查询 基本 select  条件表示法
           */
		  public function index48(){
            $where =  [
				'name'=> ['eq','何发给']  //eq 等于
				 ];
			$order = [
                'age',
                'height'=>'asc'  
			];
			
			
			
			$limit = null;  //从第三个值开始取 取6个值
			$field = 'name,age';	
			$model = new Test();
			$data = $model->select($where,$order,$limit,$field);
		
			$this->index49();
			echo Test::getlastsql();  // model 下获得最后一条sql
			dump($data);
		
		  }

		  public function index49(){
			  echo"
			  <hr/>
			  <pre>
               \$where =  [
				          'name'=> ['eq','何发给']  //eq 等于
				          ];
			   \$order = null;
			   \$limit = null;
			   \$field = 'name,age';	
			   \$model = new Test();
			   \$data = \$model->select(\$where,\$order,\$limit,\$item);
			   <br/><br/><br/><br/>
			   model 层
			   return  \$this->where(\$where)->order(\$order)->limit(\$limit)->field(\$field)->select();
			   </pre>
				<hr/>
				";
		  }


		  /***
		   * limit 的用法
		   */
		  public function index50(){
			  echo'
				<hr/>
				<pre>
				$limit = 10;  //取 10条记录
				$limit = "3,6";  //从第三个值开始取 取6个值
				</pre>
				<hr/>
			  ';
		  }

			 /***
		   * 查询 某一字段的所有值 模版渲染
		   */
		  public function index51(){
			$model = new Test();
			$column = 'age';
			 $data = $model->select1($column);
			 $this->index52();
			 echo Test::getlastsql();  // model 下获得最后一条sql
         dump($data);
		  }
		
		  public function index52(){
			  echo"
			  <hr/>
			  <pre>
			     \$model = new Test();
			     \$column = 'age';     // 查询的字段
                 \$data = \$model->select1(\$column);
                 <br/><br/><br/><br/>
				  model 层
				  return \$this->column(\$column);
			  </pre>
			  <hr/>
			  ";	  
		  }

           /***
		   * 查询 某一字段的所有值 去重
		   */
		  public function index53(){
			$model = new Test();
			$column = 'age';
			$distinct = true;
			 $data = $model->select2($column,$distinct);
			 $this->index54();
			 echo Test::getlastsql();  // model 下获得最后一条sql
         dump($data);
		  }

		  public function index54(){
			 echo"
			 <hr/>
			 <pre>
			 \$model = new Test();
			 \$column = 'age';
			 \$distinct = true;
			 \$data = \$model->select2(\$column,\$distinct);
			 <br/><br/><br/><br/>
			  model 层
			  return \$this->Distinct(\$distinct)->column(\$column);  
			 </pre>
			 <hr/>
			 ";
			}



           /**
			*  去重 唯一 $distinct 的用法
		    */
		  public function index55(){
			  echo'
			  <hr/>
			  <pre>
			  $distinct = null;  //不去重
			  $distinct = "false";  //去重
			  $distinct = true;     //去重
			 </pre>
			 <hr/>
			  ';
		  }

         /**
		  * 从数据库查出的某一列值 一维数组 的模版渲染
		  */
		  public function index56(){
			$model = new Test();
			$column = 'age';
			$distinct = null;
			 $data = $model->select2($column,$distinct);
			
		
			 $this->assign('data',$data);
			 $this->index57();
			 echo Test::getlastsql();  // model 下获得最后一条sql
			 return $this->fetch();
		  }

          public function index57(){
				echo'
				<hr/>
				<pre>
				$column = \'age\';
				$distinct = null;
				连贯操作 ->Distinct($distinct)->column($column);
	               {volist name="data" id="vo" }
	               {\$vo}<br/>
                	{/volist}
	
				</pre>
				<hr/>
				';       
			  }


        /**
		 * group 去重
		 */
		public function index58(){
			$model = new Test();
			$group = 'age';
			$column = 'age';
			$data = $model->select3($group,$column);
			dump($data);
		}
	   
		/**
		 * field 查询哪些字段
		 */
		public function index59(){
		  echo"
		  <hr/>
		  <per>
		  \$field = null;  //全部字段
		  \$field = 'name'; //一个字段
		  \$field = 'name,age';  //两个字段
		  </pre>
		  <hr/>
		  ";
		}


           /**
           * 二维数组的模版渲染
           */
		  public function index60(){
            $where =  [
				'name'=> ['eq','何发给']  //eq 等于
				 ];
			$order = [
                'age',
                'height'=>'asc'  
			];
			$limit = null;  //从第三个值开始取 取6个值
			$field = 'name,age';	
			$model = new Test();
			$data = $model->select($where,$order,$limit,$field);
	    	
			echo Test::getlastsql();  // model 下获得最后一条sql
			$this->index61($data);
			$this->assign('data',$data);
			return $this->fetch();
			
		  }


		  public function index61($data){
			  echo'
		  <pre>
		  $field = \'name,age\';
          连贯操作为   $this->where($where)->order($order)->limit($limit)->field($field)->select();

		  $this->assign(\'data\',$data);

		  {volist name="data" id="vo" }
		  {$vo.name}------{$vo.age}<br/>
		  {/volist}

           </pre>
			';
			dump($data);
		  }

		  	 /***
		   * 查询 某两个字段的所有值 并以一个为键名 一个为键值 
		   */
		  public function index62(){
			$model = new Test();
			$column = "name,age,height";  //第一个是键名 后面的是键值
			 $data = $model->select1($column);
			 $this->index63();
			 echo Test::getlastsql();  // model 下获得最后一条sql
         dump($data);
		  }
		

		  public function index63(){
			  echo"
			  <hr/>
			  <pre>
			\$model = new Test();
			\$column = \"name,age,height\";  //第一个是键名 后面的是键值
			 \$data = \$model->select1(\$column);
			 <br/><br/><br/><br/>
			  model 层
			  return \$this->column(\$column);
			  </pre>
			  <hr/>
			  ";
       
		  }

         /***
		  * 查询 不等于
		  */
		  public function index64(){
          $where = [
			  'age' => ['neq','100']
		  ]; 
		  $order = null;
		  $limit = null;
		  $field = null;
		  $model = new Test();
		  $data = $model->select($where,$order,$limit,$field);
		  $this->index65();
		  dump($data);
		  }

		  public function index65(){
				echo'
				<hr/>
				<pre>
				$where = [
					\'age\' => [\'neq\',\'100\']  //不等于
				]; 
				$order = null;
				$limit = null;
				$field = null;
				$model = new Test();
				$data = $model->select($where,$order,$limit,$field);
				<br/><br/><br/><br/>
				model 层
				return $this->where($where)->order($order)->limit($limit)->field($field)->select();
				
				</pre>
				<hr/>
				';
            }


          /***
		  * 查询 在..之间 between 在1到5之间 则包括1和5
		  */
		  public function index66(){
			  $val = '25,87';  // 条件内容
			$where = [
				'age' => ['between',$val]
			]; 
			$order = null;
			$limit = null;
			$field = null;
			$model = new Test();
			$data = $model->select($where,$order,$limit,$field);
			$this->index67();
			dump($data);
			}

			public function index67(){
				echo'
				<hr/>
				<pre>
				$val = \'25,87\';  // 条件内容
				$where = [
					\'age\' => [\'between\',$val]  //在。。。之间
				]; 
				$order = null;
				$limit = null;
				$field = null;
				$model = new Test();
				$data = $model->select($where,$order,$limit,$field);
				</pre>
				<hr/>
				';
				}

          /***
		  * 查询 都有哪些值
		  */
				public function index68(){
					$val = '何看v,何发给你看,何发给13stt'; //条件内容
					$where = [
						'name' => ['in',$val]  //都有哪些值  
					]; 
					$order = null;
					$limit = null;
					$field = null;
					$model = new Test();
					$data = $model->select($where,$order,$limit,$field);
					$this->index69();
					dump($data);
					}

					public function index69(){
					echo"
					<hr/>
					<pre>
					\$val = '何看v,何发给你看,何发给13stt'; //条件内容
					\$where = [
						'name' => ['in',\$val]  //都有哪些值  
					]; 
					\$order = null;
					\$limit = null;
					\$field = null;
					\$model = new Test();
					\$data = \$model->select(\$where,\$order,\$limit,\$field);
					<br/><br/><br/><br/>
					model 层
					return \$this->where(\$where)->order(\$order)->limit(\$limit)->field(\$field)->select();
					</pre>
					<hr/>
					";
					
					}

          /***
		  * 查询 都有哪些值 用数组表示条件
		  */
          public $val =  ['何看v','何发给你看','何发给13stt']; //条件内容

		  public function index70(){
			$val = $this->val; //获得条件 数组形式
 		
			$where = [
				'name' => ['in',$val]  //都有哪些值  
			]; 
			$order = null;
			$limit = null;
			$field = null;
			$model = new Test();
			$data = $model->select($where,$order,$limit,$field);
			$this->index71();
			dump($data);
			}
			public function index71(){
				echo'
				<hr/>
				<pre>
				$val = $this->val; //从公共属性中 获得条件 数组形式
			 
				$where = [
					\'name\' => [\'in\',$val]  //都有哪些值  
				]; 
				$order = null;
				$limit = null;
				$field = null;
				$model = new Test();
				$data = $model->select($where,$order,$limit,$field);
				$this->index71();
				dump($data);
				</pre>
				<hr/>
				';
				}


				/**
				 * 条件 多条件 and关系
				 */
				public function index72(){
					$val =  ['何看v','何发给你看','何发给13stt']; //条件内容 数组形式
				    $val2 = '26'; 
					$where = [
						"name" => ["in",$val],  //都有哪些值  
						"age" =>["eq",$val2]
					]; 
					$order = null;
					$limit = null;
					$field = null;
					$model = new Test();
					$data = $model->select($where,$order,$limit,$field);
					$this->index73();
					dump($data);
					}

					public function index73(){
						echo'
						<hr/>
						<pre>
						$val =  [\'何看v\',\'何发给你看\',\'何发给13stt\']; //条件内容 数组形式
						$val2 = "26"; 
						$where = [
							"name" => ["in",$val],  //都有哪些值  
							"age" =>["eq",$val2]    // 两个条件 条件之间是and 关系
						]; 
						$order = null;
						$limit = null;
						$field = null;
						$model = new Test();
						$data = $model->select($where,$order,$limit,$field);
						<br/><br/><br/><br/>
				     	model 层
						 return $this->where($where)->order($order)->limit($limit)->field($field)->select();
						</pre>
						<hr/>
						';
					}

			     /**
				 * 条件 多条件 or 或者关系 查询姓名是 何看v','何发给你看 或者年龄是25岁的数据
				 */
				public function index74(){
					$name =  ['何看v','何发给你看']; //条件内容 数组形式
				    $age = 25; 
				
					$where = function($query)use($age,$name){
						$query->where("name","in",$name)
						      ->whereOr("age","eq",$age);    
						};

					$order = null;
					$limit = null;
					$field = null;
					$model = new Test();
					$data = $model->select($where,$order,$limit,$field);
					$this->index75();
					dump($data);
					}

					public function index75(){
						echo'
						<hr/>
						<pre>
						查询姓名是 何看v ,何发给你看 或者年龄是25岁的数据
						$name =  [\'何看v\',\'何发给你看\']; //条件内容 数组形式
						$age = 25; 
					
						$where = function($query)use($age,$name){
							$query->where("name","in",$name)
								  ->whereOr("age","eq",$age);    
							};
	
						$order = null;
						$limit = null;
						$field = null;
						$model = new Test();
						$data = $model->select($where,$order,$limit,$field);
						<br/><br/><br/><br/>
				     	model 层
						 return $this->where($where)->order($order)->limit($limit)->field($field)->select();
					
						</pre>
						<hr/>
						';
						}
                        /***
						 * 在模版页 使用条件判断 switch 地址栏传参
						 */
						public function index76(){

							return $this->fetch();
						}
                          /***
						 * 在模版页 使用条件判断 between 地址栏传参
						 */
						public function index77(){

							return $this->fetch();
						}

                           /***
						 * 在模版页 使用条件判断 if 地址栏传参
						 */
						public function index78(){

							return $this->fetch();
						}

                         /***
						 * 调用另一个模块（控制器）的函数的方法
						 */
						public function index79(){
							$this->index80();
							echo'<br/><font size="3" color="red">这是tp/index/index78 要调用tp/zshs/index32 </font><br/>';
							$model = new \app\tp\controller\Zshs;
							$model->index32();
                         }

						 public function index80(){
							echo'
							<hr/>
							<pre>
							$model = new \app\tp\controller\Zshs;
							$model->index32();
							</pre>
							<hr/>
							';

						 }

    /***
     * 重定向
	 */
	public function index81(){
		$name = "get传参数";
		$this->redirect('Zshs/index33',array('name'=>'SDFSKLN'));

	}

/**
 * 文件下载
 */
public function index82(){
	
	$name = input('get.name'); //xxx.pdf 才可以
	dump($name);
    $file_name = $name;     //下载文件名    
    // $file_dir = '/opt/lampp/htdocs/t5/application/home1/download/';    //对的地址
    $file_dir = '/opt/lampp/htdocs/t5/note/download/';   
	// echo $file_dir.$file_name;
	$this->index83();
//检查文件是否存在    
if (! file_exists ( $file_dir.$file_name )) {    
echo "文件找不到";    
exit ();    
} else {    
//打开文件    
$file = fopen ( $file_dir . $file_name, "r" );    
//输入文件标签     
Header ( "Content-type: application/octet-stream" );    //txt 文件可以用

Header ( "Accept-Ranges: bytes" );    
Header ( "Accept-Length: " . filesize ( $file_dir . $file_name ) );    
Header ( "Content-Disposition: attachment; filename=" . $file_name );    
//输出文件内容     
//读取文件内容并直接输出到浏览器    
echo fread ( $file, filesize ( $file_dir . $file_name ) );    
fclose ( $file );    
exit ();    
}
}

      public function index83(){
          echo'
		  <hr/>
		  <pre>
		  $name = input(\'get.name\'); //xxx.pdf 才可以
		  dump($name);
		  $file_name = $name;     //下载文件名    
		  // $file_dir = \'/opt/lampp/htdocs/t5/application/home1/download/\';    //对的地址
		  $file_dir = \'/opt/lampp/htdocs/t5/note/download/\';   
		  // echo $file_dir.$file_name;
	  //检查文件是否存在    
	  if (! file_exists ( $file_dir.$file_name )) {    
	  echo "文件找不到";    
	  exit ();    
	  } else {    
	  //打开文件    
	  $file = fopen ( $file_dir . $file_name, "r" );    
	  //输入文件标签     
	  Header ( "Content-type: application/octet-stream" );    //txt 文件可以用
	  
	  Header ( "Accept-Ranges: bytes" );    
	  Header ( "Accept-Length: " . filesize ( $file_dir . $file_name ) );    
	  Header ( "Content-Disposition: attachment; filename=" . $file_name );    
	  //输出文件内容     
	  //读取文件内容并直接输出到浏览器    
	  echo fread ( $file, filesize ( $file_dir . $file_name ) );    
	  fclose ( $file );    
	  exit ();    
	  }
	  }

		  </pre>
		  <hr/>
               ';
             }

			 /***
			  * 地址栏图标
			  */
public function index84(){

	echo'
	<hr/>
	见jQuery js的案例
	&lt;link href="__ROOT__/tb/js.ico" type="image/x-icon" rel="shortcut icon" /&gt;
	<hr/>
	';
}

/**
 * 访问api 获得json 转成数组
 */
public function index85(){
	$file_contents = file_get_contents('https://www.hyhthjk.com.cn/index/goods/xcx');
	$list = json_decode($file_contents,true);
	$this->index86();
	dump($file_contents); 
	dump($list);
}

public function index86(){
	echo'
	<hr/>
	<pre>
	$file_contents = file_get_contents(\'https://www.hyhthjk.com.cn/index/goods/xcx\');
	$list = json_decode($file_contents,true);
	</pre>
	<hr/>
	';
}

/**
 * 传统方法，json 转数组 取出数组中的一个值
 */
public function index87(){
	$array =  array(
		'id' => '1',
		'username' => '以打',
	 ); 
	  $arr = json_encode($array);
	  $this->index88();
	  dump($arr);
	  $obj = json_decode($arr);  //
	  dump($obj);   //
	  dump($obj->username);
	
}

public function index88(){
echo'
<hr/>
<pre>
$obj = json_decode($arr);
dump($obj);   
dump($obj->username);   //<b>获得对象中的值</b>
</pre>
<hr/>
';
}

/*
*session 和 变量 在比较标签中的写法
*/
public function index89(){
 $this->assign('time',time());  //当前时间
	return $this->fetch();

}

/***
 * 引用vendor  被引用文件没有namespace
 */
public function index90(){
Vendor('anli.Index');
$mod = new \Index;
$mod->index2('传参测试');
$this->index91();
}

public function index91(){
echo"
<hr/>
<pre>
wendor 类库 手动 无namespace的引入

1，在vendor 添加anli文件夹的index 文件 不要写namespace

use think\Controller;

class Index extends Controller
{
	 public function index()
    {
echo \"vendor 手动添加案例\";

	}

	public function index2(\$arr)
    {
echo \"vendor 手动添加案例,引入参数\".\$arr;

	}
}

2在控制器 在函数里引用
public function index90(){
Vendor('anli.Index');
\$mod = new \Index;   // 注意反斜杠
\$mod->index2('传参测试');
}


</pre>

";

}


/***
 * 引用vendor  被引用文件没有namespace
 */
public function index92(){
Vendor('anli.anli2.Index#api');
$mod = new \Index;
$mod->index2('传参测试');
$this->index93();
}

public function index93(){
	echo'
	<hr/>
	<pre>
	wendor 类库 手动 无namespace的引入

	1，在vendor 添加anli文件夹的index 文件 不要写namespace
	use think\Controller;

	
	2在控制器 在函数里引用
	Vendor(\'anli.anli2.Index#api\');
	$mod = new \Index;
	$mod->index2(\'传参测试\');
	</pre>
	';
	
	}

  /**
   * 退出登录 success成功跳转
   */
	public function index94(){
	  echo'案例见 http://www.2018a.com/47.94.136.51/t5/public/admin/Index/index
	  <hr/>
	  <pre>
	  Session::delete(\'name\',\'user_id\');
	  Session::delete(\'name\',\'user_info\');
	  //执行成功 返回登录界面
	  $this->success(\'注销成功，正在返回\',\'login/index\');
	  </pre>
	 
	  ';
	}
	
	/**查看版本
	*
	*/
	public function index95(){
		echo THINK_VERSION;
	}

	public function index96(){
		Vendor('anli.anli2.Index#api');
$mod = new \Index;
$mod->index3();
	}


//域名ip 对照
public function index97(){
	return $this->fetch();
}

//模板 if判断 
public function index98(){
	$data["0"]["state"] = "显示";
	$data["0"]["name"] = "王某";
	$this->assign('data',$data);
	return $this->fetch();
}
  


}